package Objects
{
	import Native.NativeBitmap;
	
	import Tools.BitmapTool;
	
	import flash.display.BitmapData;

	public class GameBitmap extends GameObject
	{
		private var lastFrame:BitmapData;
		public function GameBitmap()
		{
			super(NativeBitmap);
		}
		public function setImage(bitmapData:BitmapData,tailor:Boolean=false):void
		{
			if (bitmapData == lastFrame)
			{
				return;
			}
			lastFrame = bitmapData;
			if(tailor)
			{
				bitmapData=BitmapTool.tailor(bitmapData);
			}
			bitmap.bitmapData = bitmapData;
		}
		public function scale(width:int, height:int):void
		{
			setImage(BitmapTool.scale(bitmap.bitmapData,width,height));
		}
		public function draw(imageData:Object, x:Number, y:Number, scaleX:Number=1, scaleY:Number=1, rotation:int=0, blendMode:String="normal"):void
		{
			BitmapTool.draw(bitmap.bitmapData,imageData,x,y,scaleX,scaleY,rotation,blendMode);
		}
		public function initImage(imageData:Object,tailor:Boolean=false):void
		{
			var bitmapData:BitmapData;
			bitmapData=BitmapTool.getImageByData(imageData);
			setImage(bitmapData,tailor);
		}
		public function get bitmap():NativeBitmap
		{
			return obj as NativeBitmap;
		}
	}
}